//
//  CollectionViewCell.swift
//  YYCollectionView
//
//  Created by Domo on 2018/6/27.
//  Copyright © 2018年 知言网络. All rights reserved.
//

import UIKit

class CollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var nowPriceLabel: UILabel!
    
    @IBOutlet weak var bottomLabel: UILabel!
    
    
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var myNumBerLabel: UILabel!
    @IBOutlet weak var redView: UIView!
    
    @IBOutlet weak var exchangeBtn: UIButton!
    @IBOutlet weak var exchangeButton: UIButton!
    @IBOutlet weak var exLabel: UILabel!
    @IBOutlet weak var DEKLabel: UILabel!
    @IBOutlet weak var Mlabel: UILabel!
    @IBOutlet weak var topImageView: UIImageView!
    private var myModel:productModel? = productModel()

    var model :productModel{
        set {
            myModel = newValue;
            let url1 = URL( string:String(format: "http://renedescartes.io%@", (myModel?.myimages)!))
            topImageView?.sd_setImage(with: url1, placeholderImage: UIImage.init(named: ""), options: [], progress: nil, completed:nil)
                
            DEKLabel.text = myModel?.dke
             DEKLabel.text = String(format: "%@ dke", (myModel?.dke)!)
            DEKLabel.adjustsFontSizeToFitWidth = true
            Mlabel.text = String(format: "%@ CD", (myModel?.m)!)
            Mlabel.adjustsFontSizeToFitWidth = true
            Mlabel.snp.makeConstraints { (make) in
                make.left.equalTo(DEKLabel)
                make.top.equalTo(15)
                make.size.equalTo(CGSize(width: 150, height: 18))
            }
            exLabel.text = myModel?.extra_n
            
            
            let attrMStr = NSMutableAttributedString()
            let attacmentM_baozhi = NSTextAttachment()
            attacmentM_baozhi.image = UIImage(named: "fire@2x")
            attacmentM_baozhi.bounds = CGRect(x: 5, y: 0, width: 12, height: 12)
            
            var attrMStrbaozhi : NSAttributedString = NSAttributedString(string: "")
            
            
            attrMStrbaozhi = NSAttributedString(string: String(format: "    ext%%%@ MT", (myModel?.extra_n)!))
            
            let attacmentM_baozhi2 = NSAttributedString(attachment: attacmentM_baozhi)
            
            attrMStr.append(attacmentM_baozhi2)
            attrMStr.append(attrMStrbaozhi)
            
            exLabel.attributedText = attrMStr;

            //exLabel.text = String(format: "ext%%%@ MT", (myModel?.extra_n)!)
            exLabel.adjustsFontSizeToFitWidth = true
            
            
            
            
            //在这里给cell里的属性赋值
            myNumBerLabel.text = String(format: "%@", (myModel?.shengyu)!)
            myNumBerLabel.adjustsFontSizeToFitWidth = true
            myNumBerLabel.textAlignment = .center
        
        }
        get
        {
            return (self.myModel)!
            
        }
    }
        
      
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.layer.cornerRadius = 5
        self.layer.borderWidth = 1;
        
        //边框颜色
        self.layer.borderColor = UIColor("#4D579A")?.cgColor
        
        // Initialization code
//        self.redView.layer.cornerRadius = 25
//        self.redView.snp.makeConstraints { (make) in
//            make.centerX.centerY.equalTo(0)
//            make.size.equalTo(CGSize(width: 50, height: 50))
//        }
//        self.redView.backgroundColor = UIColor.red
        
        
        self.bgView.backgroundColor = UIColor("#060D32")
        //self.titleLabel.textColor = UIColor.white
        self.backgroundColor = UIColor("#060D32")
        self.bottomLabel.text = XALanguageManager.getString(key: "*币价每分钟实时刷新，以实际支付价格为准")
        self.bottomLabel.numberOfLines = 0
        
        self.bottomLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(self).offset(-5)
        }
        
        self.bottomLabel.adjustsFontSizeToFitWidth = true
        
        self.nowPriceLabel.text = XALanguageManager.getString(key: "当前购买价格")
        self.exchangeButton.backgroundColor = UIColor("#297EFB")
        self.exchangeButton.setTitle(XALanguageManager.getString(key: "exchange"), for: .normal)
        self.exchangeButton.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.size.equalTo(CGSize(width: 70, height: 19))
            make.right.equalTo(self).offset(-15)
        }
        
        self.exchangeButton.layer.cornerRadius = 3;
        
    }
    
    
    @IBAction func ChangeAction(_ sender: Any) {
        
        let PopTopOrBottomOutView = exchangeDKEView()
        PopTopOrBottomOutView.mywindow = self.window
        PopTopOrBottomOutView.numberM = myModel?.m!as! NSString
        
        
        PopTopOrBottomOutView.exNStr = myModel?.extra_n! as! NSString
        PopTopOrBottomOutView.dkeStr = myModel?.dke! as! NSString
        PopTopOrBottomOutView.goods_idStr = myModel?.ids! as! NSString
        PopTopOrBottomOutView.topOrBottomViewStartFrame = CGRect.init(x: 0, y: kScreenHeight, width: kScreenWidth - 0, height: 330)
        PopTopOrBottomOutView.addAnimateFromBottom()
    }
    
    
    
}
